/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jay9downloader;

import java.awt.Dimension;
import javax.swing.event.ListSelectionEvent;
import org.jdesktop.swingx.JXTable;

/**
 *
 * @author Jonas
 */
public class VideoTable extends JXTable {

    public VideoTable() {
        super();
        this.setModel(new VideoTableModel());
        this.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("#");
        this.getTableHeader().getColumnModel().getColumn(1).setHeaderValue("Title");
        this.getTableHeader().getColumnModel().getColumn(2).setHeaderValue("Progress");
        this.getTableHeader().getColumnModel().getColumn(3).setHeaderValue("Status");
        this.getTableHeader().getColumnModel().getColumn(4).setHeaderValue("Play");
        this.getTableHeader().repaint();
        this.setRowHeight(25);
        this.setIntercellSpacing(new Dimension(10, 10));
        this.setSortable(false);
//        this.setRolloverEnabled(true);
//        this.addHighlighter(
//            new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW,
//            getForeground(),
//            getBackground()));
    }

    @Override
    public void setValueAt(Object aValue, int row, int column) {
        super.setValueAt(aValue, row, column);
    }

    public void updateProgressCellRenderer() {
        for (int i = 0; i < this.getTableHeader().getColumnModel().getColumnCount(); i++) {
            if(this.getTableHeader().getColumnModel().getColumn(i).getHeaderValue().equals("Progress")) {
                this.getColumnModel().getColumn(i).setCellRenderer(new TableProgressBar());
            } else if(this.getTableHeader().getColumnModel().getColumn(i).getHeaderValue().equals("Play")) {
                this.getColumnModel().getColumn(i).setCellRenderer(new videoTablePlayButton());
            }
        }
    }

    @Override
    public void valueChanged(ListSelectionEvent e) {
        super.valueChanged(e);
        if(this.getSelectedRows().length >= 1) {
            //TODO update textVideo* JTextFields
        }
    }

}
